package cn.itcast.dao.impl;

import cn.itcast.dao.UserDao;
import cn.itcast.domain.User;
import cn.itcast.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDaoImpl implements UserDao {
    @Override
    public void register(User user) {
        JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());
        String sql="insert into user values(null,?,?,?)";
        jdbcTemplate.update(sql, user.getUsername(), user.getPassword(), user.getGender());


    }

    @Override
    public User login(User user) {
        JdbcTemplate jdbcTemplate=new JdbcTemplate(JDBCUtils.getDataSource());

        String sql="select * from user where username=? and password=?";
        Object[] parms={user.getUsername(),user.getPassword()};
        User user1 = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), parms);
        return user1;

    }


}
